from ..ModelInterface import Model, Widget, Param
from ..node import Node, Link


class ConstType(Model):
    def get_title(self):
        return "常量"

    def get_category(self):
        return "基础"

    def get_in(self):
        return []

    def get_out(self):
        return [
            Param("字符", "text"),
        ]

    def get_widget(self):
        return [Widget("text", "prop1", "常量值")]

    def process(self, node: Node, links: list[Link]) -> list[Link]:
        return links


class PrintStr(Model):
    def get_title(self):
        return "后端输出"

    def get_category(self):
        return "调试"

    def get_in(self):
        return [Param("字符", "text"), Param("数字", "number")]

    def get_out(self):
        return []

    def get_widget(self):
        return []

    def process(self, node: Node, links: list[Link]) -> list[Link]:
        # 打印
        for input in node.inputs:
            if input.value:
                print(input.value)

        return links


class WebPrintStr(Model):
    def get_title(self):
        return "前端输出"

    def get_category(self):
        return "调试"

    def get_in(self):
        return [Param("字符", "text")]

    def get_out(self):
        return []

    def get_widget(self):
        return [
            Widget("text", "文字", "文字", {'editable': False}),
        ]

    def process(self, node: Node, links: list[Link]) -> list[Link]:
        # 打印
        node.widgetValues[0] = node.inputs[0].value

        return links


class ClickTrigger(Model):
    def get_title(self):
        return "触发"

    def get_category(self):
        return "调试"

    def get_in(self):
        return []

    def get_out(self):
        return [
            Param("数字", "number"),
        ]

    def get_widget(self):
        return [
            Widget("button", "按钮", "按钮", prop={'trigger': True}),
        ]

    def process(self, node: Node, links: list[Link]) -> list[Link]:
        node.outputs[0].value = 1
        return links


class Example(Model):
    def get_title(self):
        return "示例"

    def get_category(self):
        return "基础"

    def get_in(self):
        return []

    def get_out(self):
        return [
            Param("文字", "text"),
        ]

    def get_widget(self):
        return [
            Widget("slider", "滑动条", "0.5", {"min": 0, "max": 1}),
            Widget("number", "数字", "45", {"min": 0, "max": 100}),
            Widget("combo", "组合", "red", {"values": ["red", "green", "blue"]}),
            Widget("text", "文字", "文字"),
            Widget("text", "多行文字", "多行文字", {"multiline": True}),
            Widget("toggle", "开关", False, {"on": "enabled", "off": "disabled"}),
            Widget("button", "按钮", "按钮"),
        ]

    def hi(self):
        print("hello")
